package _33define;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class Demo3 {
    public static void main(String[] args) {
        int numb=0;
        String input="atach";
        String[] output= {"cat", "bt", "hat", "tree"};
        Map<Character,Integer> map=new HashMap<>();
        for (char c : input.toCharArray()) {
            map.put(c,map.getOrDefault(c,0)+1);
        }
        System.out.println(map);
        for (String s : output) {
            Map<Character,Integer> map1=new HashMap<>();
            for (char c : s.toCharArray()) {
                map1.put(c,map1.getOrDefault(c,0)+1);
            }
            numb+=numbMapContainAll(map1,map);
        }
        System.out.println("输出："+numb);
    }
    public static int numbMapContainAll(Map<Character,Integer> a,Map<Character,Integer> b){
        String all="";
        Set<Map.Entry<Character, Integer>> ent1=a.entrySet();
        Set<Map.Entry<Character, Integer>> ent2=b.entrySet();
        for (Map.Entry<Character, Integer> cha : ent1) {
            char key=cha.getKey();
            Integer value=cha.getValue();
            for (Map.Entry<Character, Integer> cha2 : ent2) {
                if (cha2.getKey()==key&&cha2.getValue()==value){
                    all+=key;
                    break;
                }
            }
            System.out.println(all);
        }
        return all.length();
    }
}
